package com.yibo.server;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * 如果eureka设置了security权限认证，那么必须添加此配置，其他客户端服务才能通过认证密码进行注册
 */
@Configuration
@EnableWebSecurity
public class EurekaSecurityConfig extends WebSecurityConfigurerAdapter {

    /**
     * 在旧版本的springcloud中添加security权限验证只需要在application.yml中添加就可以了，新版
     * 必须要重写一下方法
     *
     * @param http        http验证
     * @throws Exception  异常
     */
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        super.configure(http);
    }

    /**
     * 主要作用是忽略 hystrix 和 turbine熔断监控url
     * @param web    web验证
     * @throws Exception   异常
     */
    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/actuator/hystrix.stream","turbine.stream");
    }
}
